#include <cstdio>
#include <cstring>
#include <algorithm>

#define max_digits 255
using namespace std;

class big_integer{
public:
    int digit[max_digits];
    int size;

    void init(){
        for (int i = 0; i < max_digits; i++)
            digit[i] = 0;
        size = 0;
    }

    void set_num(char string[]){
        init();
        int length = strlen(string);
        for (int i = length - 1, count = 0, weight = 1, temp_num = 0; i >= 0; i--){
            temp_num += (string[i] - '0')*weight;
            weight *= 10;
            count++;
            if (count == 4 || i == 0){
                digit[size++] = temp_num;
                temp_num = 0;
                count = 0;
                weight = 1;
            }
        }
    }

    void out_put(){
        for (int i = size - 1; i >= 0; i--){
            if (i != size - 1)
                printf("%04d", digit[i]);
            else
                printf("%d", digit[i]);
        }
        printf("\n");
    }

    bool operator < (const big_integer &big_num) const {
        if (size != big_num.size)
            return size < big_num.size;
        else{
            for (int i = size - 1; i >= 0; i--){
                if (digit[i] != big_num.digit[i])
                    return digit[i] < big_num.digit[i];
            }
        }
        return false;
    }

} big_nums[100];

int main(int argc, char const *argv[]){
    int N;
    while (scanf("%d", &N) != EOF) {
        for (int i = 0; i < N; i++){
            char input_string[1005];
            scanf("%s", input_string);
            big_nums[i].set_num(input_string);
        }
        sort(big_nums, big_nums + N);

        for (int i = 0; i < N; i++)
            big_nums[i].out_put();
    }

    return 0;
}